package com.atguigu.yygh.hosp.controller;


import com.atguigu.yygh.common.utils.R;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.model.hosp.HospitalSet;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import io.swagger.annotations.ApiParam;
import jdk.nashorn.internal.ir.ReturnNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/hosp/hospital")
@Api(tags = "医院管理")
//@CrossOrigin
public class HospController {

    @Autowired
    private HospitalService hospitalService;


    @ApiOperation("根据ID获取医院详情")
    @PostMapping("/getById/{id}")
    public R getById(@ApiParam(value = "医院ID",required = true)@PathVariable String id){

        Hospital hospital=hospitalService.getById(id);
        return R.ok().data("hospital",hospital);
    }

    @ApiOperation("根据code获取医院详情")
    @PostMapping("/getByCode/{hoscode}")
    public R getByCode(@ApiParam(value = "code",required = true)@PathVariable String hoscode){

        Hospital hospital=hospitalService.getByCode(hoscode);
        return R.ok().data("hospital",hospital);
    }

    @ApiOperation("上线与下线")
    @PostMapping("/updateStatus/{id}/{status}")
    public R updateStatus(@ApiParam(value = "ID",required = true)@PathVariable String id,
                          @ApiParam(value = "状态",required = true)@PathVariable Integer status){

        hospitalService.updateStatus(id,status);

        return R.ok();
    }

    @ApiOperation("分页条件查询")
    @PostMapping("/pageList/{page}/{size}")
    public R pageList(@ApiParam(value = "页码",required = true)@PathVariable Integer page,
                      @ApiParam(value = "数量",required = true)@PathVariable Integer size,
                      @ApiParam(value = "查询条件")@RequestBody HospitalQueryVo hospitalQueryVo){

        Map<String, Object> map = hospitalService.pageList(hospitalQueryVo, page, size);


        return R.ok().data("pages",map);
    }


    @ApiOperation("根据医院名称获取医院信息")
    @PostMapping("/getListByName/{hosname}")
    public R getListByName(@ApiParam(value = "医院名称",required = true)@PathVariable String hosname){
        List<Hospital> list = hospitalService.getListByName(hosname);
        return R.ok().data("list",list);


    }

    }
